package com.wzcl.app.dao.model;


import com.alibaba.fastjson.annotation.JSONField;
import com.wzcl.app.dao.model.common.Base;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name = "UserCourse",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = {"userId", "courseId","spec"})
        },
        indexes = {
                @Index(columnList = "userPhone")
        }
)
@ApiModel(value = "用户课程表")
@EntityListeners(AuditingEntityListener.class)
public class UserCourse implements Base {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "用户id")
    private Integer userId;

    @ApiModelProperty(value = "用户手机号")
    private String userPhone;

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name = "courseId")
    @ApiModelProperty(value = "课程id")
    private Course course;

    @ApiModelProperty(value = "规格")
    private String spec;

    @CreatedDate
    @ApiModelProperty(value = "创建时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    public UserCourse() {
    }

    public UserCourse(Integer userId, String userPhone, Course course) {
        this.userId = userId;
        this.userPhone = userPhone;
        this.course = course;
    }

    @Override
    public String toString() {
        return "UserCourse{" +
                "id=" + id +
                ", userId=" + userId +
                ", userPhone='" + userPhone + '\'' +
                ", course=" + course +
                ", spec='" + spec + '\'' +
                ", createTime=" + createTime +
                '}';
    }
}
